<template>
  <div class="paycode">
    <div id="qrcode" ref="qrCodeUrl"></div>
  </div>
</template>

<script>
import QRCode from 'qrcodejs2'
  export default {
    props: ['showCode'],
    data() {
      return {
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.crateQrcode()
      })
    },
    unmounted() {
      let barcode = document.getElementById('qrcode')
      barcode.innerHTML = ''
    },
    methods: {
      // 生成二维码
    crateQrcode() {
      console.log(this.showCode,111)
      let barcode = document.getElementById('qrcode')
      let qrcode = new QRCode(barcode, {
          // text: 'https://blog.csdn.net/weixin_42601136', // 需要转换为二维码的内容，链接二维码
          text:this.showCode, // 需要转换为二维码的内容，文字二维码
          width: 200,
          height: 200,
          colorDark: '#000000',
          colorLight: '#ffffff',
          correctLevel: QRCode.CorrectLevel.L
      })
  },
    },
  }
</script>

<style scoped lang="scss">
/* @import url(); 引入css类 */
 ::v-deep #qrcode {
    text-align: center;
    img {
      display: inline-block !important;
    }
  }
</style>